#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )

// Random testing for the Minion Card (enum 7)
int main()
{
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	struct gameState G;
	int randomSeed;
	int m;
	int numPlayer = 2;
	int i, j;
	int num_tests = 5000;
	int choice = 0;		// 1 = coins, all other values redraw
	int hand_1, hand_2;	// Players' hand size before minion played.
	int coins;			// First player's coins before minion played.
	
	srand(time(NULL));
	randomSeed = (rand() % 10)+1;
	m = initializeGame(numPlayer, k, randomSeed, &G);
	
	for(i=0;i<num_tests;i++)
	{
		// Set hand sizes
		G.handCount[0] = rand() % 10 + 1;
		G.handCount[1] = rand() % 10;
		G.coins = rand() % 10;
		coins = G.coins;
		hand_2 = G.handCount[1];
		hand_1 = G.handCount[0];
		G.numActions = 1;
		
		if(choice == 1)
			cardEffect(17, 1, 0, 0, &G, 0, 0);
		else
			cardEffect(17, 0, 1, 0, &G, 0, 0);

		
		// We redrew
		if(choice != 1)
		{
			printf("Testing redraw. Starting hand sizes: %i, %i. Ending: %i, %i. ", hand_1, hand_2, G.handCount[0], G.handCount[1]);
			if(G.handCount[0] == 4)
			{
				if(hand_2 > 4)
				{	
					if(G.handCount[1] == 4)
						printf("PASSED.\n");
					else
						printf("FAILED.\n");
				}
				else if(G.handCount[1] == hand_2 && hand_2 < 5)
					printf("PASSED.\n");
				else
					printf("FAILED.\n");
			}
			else
				printf("FAILED.\n");
		}
		// We went for the coins
		else
		{
			if(G.coins == coins + 2 && G.numActions == 2)
				printf("Getting coins expected %i, got %i. PASSED.\n", coins +2, G.coins);
			else
				printf("Getting coins expected %i, got %i. FAILED.\n", coins + 2, G.coins);
		}
		choice = rand() % 10;
		
		
	}
	
	
	return 0;
}